package com.qiyang.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import org.springframework.context.annotation.Bean;

/**
 * Created on 2018/4/29.
 *
 * @author sehuaqi.
 * 描述：
 */
@SpringBootApplication
@EnableZuulProxy  /*注意是 EnableZuulProxy 注解，不是EnableZuulServer注解*/
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
public class ZuulApp {

    public static void main(String args[]) {
        //执行函数
        SpringApplication.run(ZuulApp.class, args);
    }

    /**
     * 自定义路由匹配规则
     * @return
     */
    @Bean
    public PatternServiceRouteMapper serviceRouteMapper(){

        String servicePattern = "(?<name>^.+)-(?<version>v.+$)";

        String routePattern = "${version}/${name}";

        return new PatternServiceRouteMapper(servicePattern,routePattern);
    }

}
